package com.example.homework2.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;

@Controller
@RequestMapping("/thymeleaf")
public class Thymeleaf {

    @RequestMapping("/homework2")
    public void homework2(String username, MultipartFile uploadFile) throws IOException{
        System.out.println(username);
        //获得上传文件名称
        String originalFilename = uploadFile.getOriginalFilename();
        uploadFile.transferTo(new File("C:\\upload\\"+originalFilename));
    }
    @RequestMapping("/homework2_duo")
    public void homework2_duo(String username, MultipartFile[] uploadFile) throws IOException{
        System.out.println(username);
        //获得上传文件名称
       for (MultipartFile multipartFile : uploadFile){
           String originalFilename = multipartFile.getOriginalFilename();
           multipartFile.transferTo(new File("C:\\upload\\"+originalFilename));
       }
    }
}
